# encoding=utf-8
'''
Module: roleinfo
'''
import common.db

class RoleInfo:
    def __init__(self,ZoneID=None):
        if ZoneID is None or ZoneID==1:
            self.cursor1=common.db.connect('DMZZone1DB1').cursor()
            self.cursor2=common.db.connect('DMZZone1DB2').cursor()

        if ZoneID is None or ZoneID==2:
            self.cursor3=common.db.connect('DMZZone2DB1').cursor()

        if ZoneID is None or ZoneID==101:
            self.cursor4=common.db.connect('DMZZone101DB1').cursor()

    def get(self,ZoneID,RoleID,fields='RoleID,AccountID,RoleName,Gender'):
        if ZoneID==1:
            if (RoleID & 0x80)==0:
                cursor=self.cursor1
            else:
                cursor=self.cursor2
        elif ZoneID==2:
            cursor=self.cursor3
        elif ZoneID==101:
            cursor=self.cursor4
        else:
            return False 

        sql="select %s from dmz_game.role_info%d where RoleID = '%d'"%(fields,RoleID & 0x03,RoleID)
        cursor.execute(sql)
        return cursor.fetchone()

